package com.arcvideo.acsplayer.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.arcvideo.acsplayer.R;
import com.arcvideo.acsplayer.app.AcsPlayerApplication;
import com.arcvideo.acsplayer.utils.ToastUtil;

public class SelectVideoActivty extends Activity implements OnClickListener {

	private ImageButton mLoadUrlButton;
	private ImageButton mLoadLocalButton;
	private ImageButton mLoadServerButton;
	private ImageButton mLoadLastButton;
	private TextView mTitleText = null;
	private ImageButton mBackButton;
	private String mUrl = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select_video);
		initUi();
		initData();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.load_url :
				toUrlActivity();
				break;
			case R.id.load_local :
				toLocalActivity();
				break;
			case R.id.load_server :
				toServerActivity();
				break;
			case R.id.load_last :
				mUrl = AcsPlayerApplication.getInstance().getSpUtil().getLastPlayedUrl();
				if (!TextUtils.isEmpty(mUrl)) {
					toPlayActivity();
				} else {
					ToastUtil.showShort(this, R.string.invalid_url2);
				}
			default :
				break;
		}
	}

	/**
	 * 初始化UI
	 */
	private void initUi() {
		mBackButton = (ImageButton) findViewById(R.id.id_title_left_btn);
		mBackButton.setVisibility(View.GONE);
		mLoadUrlButton = (ImageButton) findViewById(R.id.load_url);
		mLoadUrlButton.setOnClickListener(this);
		mLoadLocalButton = (ImageButton) findViewById(R.id.load_local);
		mLoadLocalButton.setOnClickListener(this);
		mLoadServerButton = (ImageButton) findViewById(R.id.load_server);
		mLoadServerButton.setOnClickListener(this);
		mLoadLastButton = (ImageButton) findViewById(R.id.load_last);
		mLoadLastButton.setOnClickListener(this);
		mTitleText = (TextView) findViewById(R.id.id_title_text_view);
		mTitleText.setText(R.string.select_video);
	}

	/**
	 * 初始化数据
	 */
	private void initData() {

	}

	/**
	 * 进入输入数据页面
	 */
	private void toUrlActivity() {
		Intent displayIntent = new Intent(SelectVideoActivty.this, LoadUrlActivity.class);
		startActivity(displayIntent);
	}

	/**
	 * 进入本地数据页面
	 */
	private void toLocalActivity() {
		Intent displayIntent = new Intent(SelectVideoActivty.this, LoadLocalActivity.class);
		startActivity(displayIntent);
	}

	/**
	 * 进入虹视云数据页面
	 */
	private void toServerActivity() {
		Intent displayIntent = new Intent(SelectVideoActivty.this, LoadArclouldActivity.class);
		startActivity(displayIntent);
	}

	/**
	 * 进入输入数据页面
	 */
	private void toPlayActivity() {
		Intent displayIntent = new Intent(SelectVideoActivty.this, PlayActivity.class);
		displayIntent.putExtra(PlayActivity.URLTYPE, PlayActivity.FROM_LAST_PLAYED);
		displayIntent.putExtra(PlayActivity.URLDATA, mUrl);
		displayIntent.putExtra(PlayActivity.URLINDEX, 0);
		startActivity(displayIntent);
	}
}